package com.eatme.core.unionfind;

import java.util.Random;

public interface UF {

    int getSize();

    boolean isConnected(int p,int q);

    void unionElements(int p,int q);

    private static double testUF(UF uf,int m) {
        int size = uf.getSize();
        Random random = new Random();
        long startTime = System.nanoTime();
        for (int i = 0; i < m; i++) {
            int a = random.nextInt(size);
            int b = random.nextInt(size);
            uf.unionElements(a,b);
        }
        for (int i = 0; i < m; i++) {
            int a = random.nextInt(size);
            int b = random.nextInt(size);
            uf.isConnected(a,b);
        }
        long endTime = System.nanoTime();
        return (endTime-startTime)/1000000.0;
    }

    static void main(String[] args) {
        int size = 100000;
        int m = 100;
//        UnionFindV1 v1 = new UnionFindV1(size);
//        System.out.println("v1: "+testUF(v1,m)+" ms");
//        UnionFindV2 v2 = new UnionFindV2(size);
//        System.out.println("v2: "+testUF(v2,m)+" ms");
        UnionFindV3 v3 = new UnionFindV3(size);
        System.out.println("v3: "+testUF(v3,m)+" ms");
        UnionFindV4 v4 = new UnionFindV4(size);
        System.out.println("v4: "+testUF(v4,m)+" ms");
        UnionFindV5 v5 = new UnionFindV5(size);
        System.out.println("v5: "+testUF(v5,m)+" ms");
        UnionFindV6 v6 = new UnionFindV6(size);
        System.out.println("v6: "+testUF(v6,m)+" ms");
    }

}
